﻿/// <reference path="jquery-1.4.1.min.js" />

$(document).ready(function() {

    $("div.Rating").each(function() {

        var ItemID = $(this).children("INPUT[type=hidden]").val();
        var result = $(this).children("div[id=dvCurrentRate]");

        $(this).find("input[type=radio]").click(function() {
            var rate = $(this).val();
            RateIt(ItemID, rate, result);
            $(this).parent().find("input[type=radio]").attr("disabled", "disabled");
        });

        $(this).find("select").change(function() {            
            var rate = $(this).val();
            RateIt(ItemID, rate, result);
            $(this).attr("disabled", "disabled");
        });

    });
});

function RateIt(ItemID, rate, result) {

    $.getJSON("RateHandler.ashx?ItemID=" + ItemID + "&Rate=" + rate, function(output) {
        var avgRating = output[0].Rate;
        $(result).html(avgRating);
        alert("Successfully Rated!!");
    });
}